<?php
namespace app\admin\controller;
use app\admin\model\UserFollow;

use think\captcha\Captcha;
use think\Config;

class Index extends Base
{
    /**
     * 判断用户是否有Session
     */
    public function index(){
       if(!$this->islogin()){
           return  $this->redirect('Login/index');
       }else{
           return $this->fetch();
       }
    }
    /**
     * @return \think\Response
     * 二维码生成
     */
    public  function  getCaptcha(){
        $config = config('captcha');
        $Captcha = new Captcha($config);
        return $Captcha->entry();
    }

        /**
     *
     */
    public function deluserfriend()
    {
        $where['userid'] = $_REQUEST['userid'];
        $where['followid'] = $_REQUEST['friendid'];
        $UserFriendModel = new UserFollow();
        $res = $UserFriendModel->where($where)->find();
        $wheres['userid'] = $where['followid'];
        $wheres['followid'] = $where['userid'];
        $datas = $UserFriendModel->where($wheres)->find();
        if ($res) {
            $UserFriendModel->where($where)->delete();
            $data['state'] = 1;
            $data['msg'] = '删除成功';
            return json($data);
        }elseif($datas){
            $UserFriendModel->where($wheres)->delete();
            $data['state'] = 1;
            $data['msg'] = '删除成功';
            return json($data);
        }else{
            $data['state'] = 0;
            $data['msg'] = '用户信息错误';
            return json($data);
        }
    }
}
